package 二叉树相关问题.BST;

import java.util.LinkedList;

public class BSTIterator {
    LinkedList<Integer> lists;
    public BSTIterator(TreeNode root) {
       lists = new LinkedList<>();
       traverse(root);
    }
    public void traverse(TreeNode root){
        if (root==null)
            return;
        traverse(root.left);
        lists.addLast(root.val);
        traverse(root.right);
    }

    public int next() {
         return lists.removeFirst();
    }

    public boolean hasNext() {
        return lists.size()>=1;
    }
}
